package com.yx.fx.webApi.serviceImpl;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yx.fx.common.model.response.Outcome;
import com.yx.fx.sys.web.business.SysUserBusiness;
import com.yx.fx.sys.web.model.UserInfo;
import com.yx.fx.webApi.entity.BankAccessRecord;
import com.yx.fx.webApi.mapper.BankAccessRecordMapper;
import com.yx.fx.webApi.param.BankAccessRecordParam;
import com.yx.fx.webApi.service.BankAccessRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author pxb
 * @since 2021-09-17
 */
@Service
public class BankAccessRecordServiceImpl extends ServiceImpl<BankAccessRecordMapper, BankAccessRecord> implements BankAccessRecordService {

    @Resource
    private BankAccessRecordService bankAccessRecordService;

    @Resource
    private SysUserBusiness sysUserBusiness;


    /**
     * 提交结果
     * 新增走访计划
     *
     * @param param 角色数据
     * @return 是否成功
     */
    public Outcome save(BankAccessRecordParam param) {
        UserInfo userInfo = sysUserBusiness.getUserInfo();
        BankAccessRecord bankAccessRecord = Convert.convert(BankAccessRecord.class, param);
        bankAccessRecord.setCreatorId(Integer.parseInt(userInfo.getId().toString()));
        return Outcome.status(bankAccessRecordService.save(bankAccessRecord));
    }

    /**
     * 根据走访信息返回走访记录列表
     *
     * @param id
     * @return
     */
    @Override
    public Outcome getListByBankAccId(Integer id) {
        return Outcome.success(bankAccessRecordService.list(
                new QueryWrapper<BankAccessRecord>()
                        .lambda()
                        .eq(true, BankAccessRecord::getBankAccId, id))
        );
    }

    /**
     * 提交结果
     * 填写走访结果和内容
     *
     * @param param 角色数据
     * @return 是否成功
     */
    public Outcome updateById(BankAccessRecordParam param) {
        UserInfo userInfo = sysUserBusiness.getUserInfo();
        BankAccessRecord bankAccessRecord = Convert.convert(BankAccessRecord.class, param);
        return Outcome.status(bankAccessRecordService.updateById(bankAccessRecord));
    }


}
